import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from "@/components/Home.vue";
import HomePage from "@/views/HomePage.vue";
import Login from "@/views/Login.vue";
import Regist from "@/views/Regist.vue";
import UserHome from "@/components/UserHome.vue";
import AdminHome from "@/components/AdminHome.vue";
import BackendManagement from "@/admin/BackendManagement.vue";
import NewProducts from "@/views/NewProducts.vue";
import HotSales from "@/views/HotSales.vue";
import PersonalCenter from "@/user/PersonalCenter.vue";
import OrderManagement from "@/user/OrderManagement.vue"
import PersonalInformation from "@/user/personalcenter/PersonalInformation.vue";
import OrderManagement2 from "@/admin/OrderManagement2.vue";
import CustomerManagement from "@/admin/CustomerManagement.vue";
import ProductManagement from "@/admin/ProductManagement.vue";
import CategoryManagement from "@/admin/CategoryManagement.vue";
import AllBooks from "@/views/AllBooks.vue";
import Collect from "@/user/personalcenter/Collect.vue";
import FeedBack from "@/user/personalcenter/FeedBack.vue";
import SecuritySetting from "@/user/personalcenter/SecuritySetting.vue";
import ChangPwd from "@/user/personalcenter/ChangPwd.vue";
import BookDetail from "@/views/BookDetail.vue";
import Cart from "@/views/Cart.vue";

Vue.use(VueRouter)

const routes = [
  {
    path:'/',
    redirect:'/home'
  },
  {
    path: '/home',
    component:Home,
    redirect:"/home/homepage",
    children:[
      {path:'homepage', component:HomePage,meta:{title:'首页'}},
      {path:'allbooks',component: AllBooks,meta:{title:'全部书籍'}},
      {path:'hotsales', component:HotSales,meta:{title:'热销'}},
      {path:'newproducts', component:NewProducts,meta:{title:'新品'}},
      {path:'login', component:Login,meta:{title:'登录'}},
      {path:'regist', component:Regist,meta:{title:'注册'}},
      {path: "book_detail",component: BookDetail,meta:{title:'书本详情'}},

    ]
  },
  {
    path: '/userhome',
    component:UserHome,
    redirect:"/userhome/homepage",
    meta:{title:'用户主页'},
    children:[
      {path:'homepage', component:HomePage,meta:{title:'首页'}},
      {path:'allbooks',component: AllBooks,meta:{title:'全部书籍'}},
      {path:'hotsales', component:HotSales,meta:{title:'热销'}},
      {path:'newproducts', component:NewProducts,meta:{title:'新品'}},
      {path:'ordermanagement', component:OrderManagement,meta:{title:'我的订单'}},
      {path:'personalcenter', component:PersonalCenter,redirect: 'personalcenter/personalinformation',
        children:[
            {path:'personalinformation',component:PersonalInformation,meta:{title:'个人信息'}},
            {path:'changPwd', component:ChangPwd,meta:{title:'修改密码'}},
            {path:'collect', component:Collect,meta:{title:'收藏'}},
            {path:'feedback', component:FeedBack,meta:{title:'意见反馈'}},
            {path:'security_setting', component:SecuritySetting,meta:{title:'安全设置'}},

        ]},
      {path: "book_detail",component: BookDetail,meta:{title:'书本详情'}},
      {path:'cart', component:Cart,meta:{title:'购物车'}},
    ]
  },
  {
    path: '/adminhome',
    component:AdminHome,
    redirect:"/adminhome/homepage",
    meta:{title:'管理员主页'},
    children:[
      {path:'homepage', component:HomePage,meta:{title:'首页'}},
        {path:'allbooks',component: AllBooks,meta:{title:'全部书籍'}},
      {path:'hotsales', component:HotSales,meta:{title:'热销'}},
      {path:'newproducts', component:NewProducts,meta:{title:'新品'}},
      {path: "book_detail",component: BookDetail,meta:{title:'书本详情'}},
      {path:'cart', component:Cart,meta:{title:'购物车'}},
    ]
  },

    {
      path:'/backendmanagement',
      component:BackendManagement,
      redirect: '/backendmanagement/ordermanagement2',
      children: [
        {path:'ordermanagement2', component:OrderManagement2,meta:{title:'订单管理'}},
        {path:'customermanagement', component:CustomerManagement,meta:{title:'客户管理'}},
        {path:'productmanagement', component:ProductManagement,meta:{title:'商品管理'}},
        {path:'categorymanagement', component:CategoryManagement,meta:{title:'类目管理'}},
      ]
    }
]

const router = new VueRouter({
  routes,
  mode:'history'
})


router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title;  next();
  }

})
export default router
